using NUnit.Framework;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
using StructureMap.AutoMocking;

namespace ShadeTree.Binding.Tests
{
    [TestFixture]
    public class Validation_in_screen_binder
    {
        public class BindingTarget
        {
        }

        [Test]
        public void NotifyDirty_calls_the_validation_monitor()
        {
            var mocks = new RhinoAutoMocker<ScreenBinder<BindingTarget>>();
            var element = mocks.Get<IBoundScreenElement>();
            var monitor = mocks.Get<IValidationMonitor>();

            var target = new BindingTarget();

            monitor.Binder = null;

            ScreenBinder<BindingTarget> binder = mocks.ClassUnderTest;
            binder.BindToModel(target);
            binder.Validate(element);

            monitor.AssertWasCalled(x => x.ValidateField(element, target));

            /// OLD CODE
            // using (mocks.Record())
            //{
            //    monitor.Binder = null;
            //    LastCall.Constraints(new TypeOf(typeof(ScreenBinder<BindingTarget>)));

            //    monitor.ValidateField(element, target);
            //}

            //using (mocks.Playback())
            //{
            //    ScreenBinder<BindingTarget> binder = mocks.ClassUnderTest;
            //    binder.BindToModel(target);
            //    binder.Validate(element);
            //}
        }
    }
}